const conf = require("../config");
const mongoose = require("mongoose");
let DB_URL = "mongodb://"+conf.mongo_username+":"+conf.mongo_password+"@" + conf.mongo_host
	+ ":" + conf.mongo_port
	+ "/" + conf.mongo_db;
mongoose.set('useCreateIndex', true);
mongoose.connect(DB_URL, {
	useNewUrlParser: true,
	useUnifiedTopology: true,
	keepAlive: true,
	useFindAndModify: false
});
mongoose.connection.on("connected", function () {
	console.log('Mongoose connection open to ' + DB_URL);
});
mongoose.connection.on("error", function (error) {
	console.log('Mongoose connection error :' + error);
});
mongoose.connection.on("disconnected", function () {
	console.log('Mongoose connection disconnected');
});
module.exports = mongoose;